package com.ruoyi.web.controller.order;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.order.domain.NewProduct;
import com.ruoyi.order.domain.Vo.ProductVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.HotProduct;
import com.ruoyi.order.service.IHotProductService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 热销产品Controller
 * 
 * @author ruoyi
 * @date 2022-02-04
 */
@Controller
@RequestMapping("/order/hotProduct")
public class HotProductController extends BaseController
{
    private String prefix = "order/hotProduct";

    @Autowired
    private IHotProductService hotProductService;

    @RequiresPermissions("order:hotProduct:view")
    @GetMapping()
    public String hotProduct()
    {
        return prefix + "/hotProduct";
    }

    /**
     * 查询热销产品列表
     */
    @RequiresPermissions("order:hotProduct:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HotProduct hotProduct)
    {
        startPage();
        List<HotProduct> list = hotProductService.selectHotProductList(hotProduct);
        return getDataTable(list);
    }

    /**
     * 导出热销产品列表
     */
    @RequiresPermissions("order:hotProduct:export")
    @Log(title = "热销产品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HotProduct hotProduct)
    {
        List<HotProduct> list = hotProductService.selectHotProductList(hotProduct);
        ExcelUtil<HotProduct> util = new ExcelUtil<HotProduct>(HotProduct.class);
        return util.exportExcel(list, "热销产品数据");
    }

    /**
     * 新增热销产品
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存热销产品
     */
    @RequiresPermissions("order:hotProduct:add")
    @Log(title = "热销产品", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HotProduct hotProduct)
    {
        hotProduct.setCreateUser(getUserId().intValue());

        return toAjax(hotProductService.insertHotProduct(hotProduct));
    }

    /**
     * 修改热销产品
     */
    @RequiresPermissions("order:hotProduct:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        HotProduct hotProduct = hotProductService.selectHotProductById(id);
        mmap.put("hotProduct", hotProduct);
        return prefix + "/edit";
    }

    /**
     * 修改保存热销产品
     */
    @RequiresPermissions("order:hotProduct:edit")
    @Log(title = "热销产品", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HotProduct hotProduct)
    {
        hotProduct.setUpdateUser(getUserId().intValue());
        return toAjax(hotProductService.updateHotProduct(hotProduct));
    }

    /**
     * 删除热销产品
     */
    @RequiresPermissions("order:hotProduct:remove")
    @Log(title = "热销产品", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(hotProductService.deleteHotProductByIds(ids));
    }

    /**
     * 查询热销产品列表信息
     */
    @PostMapping("/getHotProductPage")
    @ResponseBody
    public TableDataInfo getHotProductPage(String productName )
    {
        startPage();
        List<ProductVo> list = hotProductService.getHotProductPage(productName);
        return getDataTable(list);
    }

}
